use std;
use std::env;
use std::fs;

fn main() {
    let args: Vec<String> = env::args().collect();

    let mut folder_path: String = String::from("");
    let mut encrypt: bool = true;
    let mut password: String = String::from("");

    let arg_length = args.len();

    for i in 0..arg_length {
        let arg = String::from(&args[i]);
        // println!("arg: {}", arg);
        if arg == "-h" || arg == "--help" {
            println!("\
                 Welcome to use Zenith AES tool! \n\n\
                 You can use this tool as: \n\
                 'aestool -f folder -p password' \n\n\
                 arguments description as: \n\n  \
                    -f <folder_path> the path to the folder which want to encrypt or decrypt\n  \
                    -e to extract the encrypt file\n  \
                    -p <password> the password which used in encrypt or decrypt\n\n  \

                    -h --help get the help doc\n\n\

                 Well! Happy to use!
                "
            );
            return;
        }

        if arg == "-f" {
            if arg_length > i + 1 {
                folder_path = String::from(&args[i + 1]);
            }
        }

        if arg == "-e" {
            encrypt = false;
        }

        if arg == "-p" {
            if arg_length > i + 1 {
                password = String::from(&args[i + 1]);
            }
        }
    }

    if password.is_empty() {
        println!("password could not be empty! please use the -h argument to get the help doc!");
        return;
    }

    if folder_path.is_empty() {
        println!("none folder path be input ! please use the -h argument to get the help doc!");
        return;
    }

    let opr = if encrypt { "encrypt" } else { "decrypt" };

    println!("start to {} of folder/file : {}", opr, folder_path);

    do_encrypt(&folder_path)
}

fn do_encrypt(folder: &String) {
    fs::read_dir(folder)
        .expect(
            format!("could not found dir in: {}", folder).as_str());
}
